package com.class04.share8;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;


/**
 * @ClassDescription: 演示共享域对象获取
 * @JdkVersion: 17
 * @Author: yxy
 * @Created: 2023/12/6 9:33
 */
@Controller
@RequestMapping("share")
@ResponseBody
public class ShareController {
    //    springmvc提供的方法  request提供了几种(了解)
//    model  modelMap  map  modelAndView
//    @GetMapping("")
    @RequestMapping("getModel")
    public String data1(Model model) {
        // 我们将数据存入模型，SpringMVC 会帮我们把模型数据存入请求域
        // 存入请求域这个动作也被称为暴露到请求域 request
        model.addAttribute("requestScopeMessageModel", "i am very happy[model]");

        System.out.println(model);
        return "target";
    }
    @RequestMapping("getModelMap")
    public void data2(ModelMap map){
        map.put("key","value");//request
        System.out.println("map = " + map);

    }

    @RequestMapping("getMap")
    public void data3(Map map){
        map.put("key","value");//request

    }

    @RequestMapping("getmodelAndView")
    public ModelAndView data4(){
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.addObject("key","value");
        modelAndView.setViewName("视图名 页面名称");
        return modelAndView;
    }
}
